<html>

<head>
	<title>Web activity manager - Visualizza log </title>
	<link href="menu/menu.css" rel="stylesheet" type="text/css"/>
	<script src="xmlLoader.js" type="text/javascript"></script>
	<script src="menu_and_sessiondata.js" type="text/javascript"></script>
	<script type="text/javascript">
		
		function init(){
		
			loadSessionData();
			generateMenu();
			loadTasks();
			loadLogs();
		}
		
		function loadTasks(){
			
			var link="/sintesiTuttiTask";
			var tasksXML=loadXMLDoc(link);
			
			var tasks=tasksXML.getElementsByTagName("elemento");
			var i;
			var innertasks="";
			
			for(i=0;i<tasks.length;i++){
						id_task=tasksXML.getElementsByTagName("id_task")[i].childNodes[0].nodeValue;
						name=tasksXML.getElementsByTagName("name")[i].childNodes[0].nodeValue;
						
						innertasks+=('<option value="'+id_task+'">'+name+'</option>');
						 
			}
			document.getElementById("selecttasks").innerHTML=innertasks;	
			
		}	
		
		function loadLogs(){
		
			var taskselezionato=document.getElementById("selecttasks").value;
			
			var link="/sintesiLogTaskAll?task="+taskselezionato;
			
			var logsXML=loadXMLDoc(link);
			
			var logs=logsXML.getElementsByTagName("elemento");
			var i;
			var newText='<th><td class="listth">Data</td><td class="listth">Ore lavorate</td><td class="listth">Operatore</td><td class="listth">Descrizione</td></th>';
			
			for(i=0;i<logs.length;i++){
				id_log=logsXML.getElementsByTagName("id_log")[i].childNodes[0].nodeValue;
				data=logsXML.getElementsByTagName("data")[i].childNodes[0].nodeValue;
				hours=logsXML.getElementsByTagName("hours")[i].childNodes[0].nodeValue;
				username=logsXML.getElementsByTagName("username")[i].childNodes[0].nodeValue;
				description=logsXML.getElementsByTagName("description")[i].childNodes[0].nodeValue;
				newText+=('<tr><td><input type="radio" name="id_log" value="'+id_log+'"></td><td>'+data+'</td><td>'+hours+'</td><td>'+username+'</td><td>'+description+'</td></tr>');
						 
			}
		
			document.getElementById("listatab").innerHTML=newText;	
				
		}	
			
		
	</script>
	<link href="style/style.css" rel="stylesheet" type="text/css"/>
</head>

<body onload="init()">
	<div class = "header">

		<div class = "headerban">
			<h1><center> WEB ACTIVITY MANAGER </center></h1>
		</div>
		
		<div class = "session_data">
			<table>
				<tr>
					<td><b>Utente: </b></td>
					<td><div id = "current_user"></div>
					</td>
				</tr>
				<tr>
					<td>
						<b>Ruolo: </b></td>
					<td><div id = "current_role" ></div>
					</td>
				</tr>
				<tr>
					<td>
						<b>Progetto: </b></td>
					<td><div id = "current_project"></div>
					</td>
				</tr>
				<tr>
					<td>
						<a href="http://localhost:4444/logout"><input type="button" value="logout"/></a>
					</td>
				</tr>
			</table>
		</div>
	</div>
	
	<!-- MENU -->
	<div class = "menu">
		<ul id="menu">
		</ul>
	</div>
	<br>
	<br>

	<div class = "funct_name">
		<h2><center> Visualizza i log di progetto </center></h2>
	</div>
	
	<!-- TABELLA DI VISUALIZZAZIONE LOGS -->
	<div class = "list">
		<form onSubmit="if(!confirm('Sei sicuro di voler eliminare questo log?')){return false;}" action="http://localhost:4444/deleteLog">
			<fieldset>
				<legend> Lista logs di progetto </legend>
				<!-- SELEZIONE TASK -->
				<label> Seleziona il task </label>
				<select id="selecttasks" name="task" onchange="loadLogs()" required>
				</select>
				<br>
				<br>
				<!-- TABELLA -->
				<table border="1" id = "listatab">
				</table>
				<br>
				<input type="submit" value="Elimina selezionato"/>
			</fieldset>
			
		</form>
	</div>
		
</body>

</html>